# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=cmake

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.0.0
pkgrel=1
pkgdesc="A cross-platform open-source make system (mingw-w64)."
arch=('any')
url="http://www.cmake.org/"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config" "${MINGW_PACKAGE_PREFIX}-qt5")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
        "${MINGW_PACKAGE_PREFIX}-curl"
        "${MINGW_PACKAGE_PREFIX}-expat"
        "${MINGW_PACKAGE_PREFIX}-libarchive"
        "${MINGW_PACKAGE_PREFIX}-zlib")
optdepends=("${MINGW_PACKAGE_PREFIX}-qt5: CMake Qt GUI")
options=('staticlibs' 'strip')
source=("http://www.cmake.org/files/v3.0/${_realname}-${pkgver}.tar.gz"
        "disable-response-files-for-msys.patch"
        "dont-install-bundle.patch")
md5sums=('21a1c85e1a3b803c4b48e7ff915a863e'
         'b715f7d6859ce82a0a1824592ab2a448'
         'fb33ace70ba863159b2c7964a9661e1e')

prepare() {
  cd ${_realname}-${pkgver}
  patch -Np1 -i ${srcdir}/disable-response-files-for-msys.patch
  patch -Np1 -i ${srcdir}/dont-install-bundle.patch
}

build() {
  pushd ${MINGW_PREFIX} > /dev/null
  export PREFIX_LIB=`pwd -W`
  popd > /dev/null

  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYSTEM=MINGW "${srcdir}"/${_realname}-${pkgver}/configure \
    --prefix=${PREFIX_LIB} \
    --system-libs \
    --no-system-expat \
    --qt-gui \
    --parallel=3 \
    --mandir=share \
    --docdir=share/doc/cmake

  plain "Start building..."
  make
}

package() {
  mkdir -p "${pkgdir}${MINGW_PREFIX}"
  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null

  cd "${srcdir}/build-${MINGW_CHOST}"
  ./bin/cmake.exe -DCMAKE_INSTALL_PREFIX:PATH=${PREFIX_WIN} -P cmake_install.cmake
}
